/**
 *  添加icp文字
 */
define(function(require,exports,module) {
    var myPub = require('./public');
    var myBirthday = require('./birthday_selet');


    var oWindowW = $(window).width();
    var oSildArea = $('.js_sildArea');			// 侧边区域 js_subBtnSave
    var oShowSilde = $('.js_showSilde');		// 侧边区域开启按钮

    var oSexSelet = $('.js_sexSelet')

    var oNickNameInput = $('.js_nickName');
    var oSubBtnSave = $('.js_subBtnSave');	 // 昵称保存按钮

    var oUserBirthday = $('.js_userBirthday');


    // 设置侧边区域效果
    oSildArea.css({'left': oWindowW});

    // 选择性别
    oSexSelet.find('li').on('click', function () {
        var _li = oSexSelet.find('li');
        var index = _li.index(this);
        _li.removeClass('active').eq(index).addClass('active');
        var _text = _li.eq(index).find('span').text();
        oSildArea.show().css({'left': oWindowW});
        oShowSilde.find('.js_sexText').text(_text).parents('.js_showSilde').attr('judge',index);
        if("男" == _text){
            _text = 'M';
        }else{
            _text = 'F';
        }
        saveGender(_text);
    });


    // 昵称保存操作
    oSubBtnSave.on('click', function () {
        var _text = oNickNameInput.val();
        if(_text == '') {
            myPub.TipLayer('请输入昵称！')
        }
        else {
            oShowSilde.find('.js_nickNameText').text(_text);
            oSildArea.show().css({'left': oWindowW});
            saveUserName(_text);
        }

    });

    // 输入昵称
    oNickNameInput.on('input propertychange', function () {
        var _oClearBtn = oNickNameInput.siblings('.js_clearBtn');
        oNickNameInput.val() == '' ? _oClearBtn.hide() : _oClearBtn.show();
    });

    // 显示侧边窗口
    oShowSilde.on('click', function () {
        var sDataSelet = $(this).attr('data-selet');
        oSildArea.show().css({'left': 0});
        oSildArea.find('.sildList').hide();

        if (sDataSelet == "nickName") {
            oSildArea.find('.nickName').show();
        }
        else if (sDataSelet == "sexSelet") {
            var judgeSex = $(this).attr('judge')*1;
            $(this).find('.js_sexText').text() == "男" ? judgeSex = 0 : judgeSex = 1;

            oSildArea.find('.js_sexSelet li').removeClass('active').eq(judgeSex).addClass('active');
            oSildArea.find('.js_sexSelet').show();
        }
    })

    // 保存昵称
    function saveUserName(userName) {
        $.ajax({
            type: "POST",
            url: "/myInfo/saveUserName",
            data:{"userName":userName},
            dataType: "json",
            success: function(data) {
                if(data.status == "success"){

                }
            },
            complete:function(xhr) {
                xhr = null;
            }
        });
    }

    // 保存性别
    function saveGender(gender) {
        $.ajax({
            type: "POST",
            url: "/myInfo/saveGender",
            data:{"gender":gender},
            dataType: "json",
            success: function(data) {
                if(data.status == "success"){

                }
            },
            complete:function(xhr) {
                xhr = null;
            }
        });
    }

    // 保存生日
    function saveBirthday(birthday) {
        $.ajax({
            type: "POST",
            url: "/myInfo/saveBrithday",
            data:{"birthday":birthday},
            dataType: "json",
            success: function(data) {
                if(data.status == "success"){

                }
            },
            complete:function(xhr) {
                xhr = null;
            }
        });
    }

    // mui生日选择
    myBirthday.SeletBirthday(oUserBirthday, function (val) {
        saveBirthday(val);
    })


});